﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LotteryVote.Entity;
using System.Data.SqlClient;

namespace LotteryVote.Data
{
    public class CompanyTypeDataAccess : DataBase
    {
        public CompanyTypeModel GetCompanyTypeByCompany(int companyId)
        {
            string sql = string.Format(@"SELECT CT.* FROM {0} LC
JOIN {1} CT ON CT.{2}=LC.{3}
WHERE LC.{4}=@{4}", LotteryCompany.TABLENAME, CompanyTypeModel.TABLENAME, CompanyTypeModel.ID, LotteryCompany.TYPEID, LotteryCompany.COMPANYID);
            return base.ExecuteEntity<CompanyTypeModel>(sql, new SqlParameter(LotteryCompany.COMPANYID, companyId));
        }
        public CompanyTypeModel GetCompanyType(int typeId)
        {
            string sql = string.Format(@"SELECT * FROM {0} WHERE {1}=@{1}", CompanyTypeModel.TABLENAME, CompanyTypeModel.ID);
            return base.ExecuteEntity<CompanyTypeModel>(sql, new SqlParameter(CompanyTypeModel.ID, typeId));
        }
        public CompanyTypeModel GetCompanyType(string typeName)
        {
            string sql = string.Format(@"SELECT * FROM {0} WHERE {1}=@{1}", CompanyTypeModel.TABLENAME, CompanyTypeModel.TYPENAME);
            return base.ExecuteEntity<CompanyTypeModel>(sql, new SqlParameter(CompanyTypeModel.TYPENAME, typeName));
        }

        public IList<CompanyTypeModel> GetAllCompanyType()
        {
            string sql = string.Format(@"SELECT * FROM {0}", CompanyTypeModel.TABLENAME);
            return base.ExecuteList<CompanyTypeModel>(sql);
        }
    }
}
